package com.tianlan.blog.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.tianlan.blog.entity.SysRoleResource;

public interface SysRoleResourceDao extends JpaRepository<SysRoleResource, Long>{
	
	List<SysRoleResource> findAllByRoleIdAndDelFlag(Integer roleId, String delFlag);
	
	@Query(value = "SELECT COUNT(1) from sys_role_resource WHERE role_id = ?1  AND del_flag = '0' "
	,nativeQuery = true)
	int isRoleResourceByRoleId(Integer roleId);

	@Transactional
	@Modifying
	@Query(value = "UPDATE sys_role_resource SET del_flag = '1' WHERE role_id = ?1"
	,nativeQuery = true)
	int deleteRoleResourceByRoleId(Integer roleId);
	
	@Transactional
	@Modifying
	@Query(value = "UPDATE sys_role_resource SET del_flag = '1' WHERE role_id = ?1 AND resource_id in (?2)"
	,nativeQuery = true)
	int deleteRoleResourceByRoleIdAndResourceIdS(Integer roleId,List<Integer> resourceIdS);
	
}
